package com.itheima.d_request_04;

import sun.security.krb5.internal.Krb5;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

@WebServlet("/RequestServlet06")
//http://localhost:8080/day07/RequestServlet03?username=zhangsan&password=123
public class RequestServlet06 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

       /* String method = request.getMethod();
        if ("GET".equals(method)){
            System.out.println(request.getQueryString());
        }else if ("POST".equals(method)){
            BufferedReader reader = request.getReader();
            String line =null;
            while ((line=reader.readLine())!=null){
                System.out.println(line);
            }
        }*/

       /* Map<String, String[]> map = request.getParameterMap();

        Set<Map.Entry<String, String[]>> entries = map.entrySet();
        for (Map.Entry<String, String[]> entry : entries) {
            String key = entry.getKey();
            String[] value = entry.getValue();
            for (String s : value) {
            System.out.println(key+"---"+s);

            }
        }*/

        String method = request.getMethod();

        if ("GET".equals(method)){
            String queryString = request.getQueryString();
            System.out.println(queryString);
        }else if ("POST".equals(method)){
            BufferedReader reader = request.getReader();
            String line;
            while ((line=reader.readLine())!=null){
                System.out.println(line);
            }
        }


    }

}